<!--
 * 后台登录页
 *
 * @Author: Reisen
 * @Date: 2025-11-26
-->
<template>
  <div class="login-wrap">
    <div class="ms-login">
      <div class="ms-title">
        <i class="iconfont icon-login-title"></i>
        <b>音乐后台管理系统</b>
      </div>
      <el-form :model="ruleForm" :rules="rules" ref="ruleForm">
        <el-form-item prop="username">
          <el-input v-model="ruleForm.username" placeholder="用户名"></el-input>
        </el-form-item>
        <el-form-item prop="password">
          <el-input type="password" v-model="ruleForm.password" placeholder="密码"
            @keyup.enter.native="submitForm"></el-input>
        </el-form-item>
        <div class="login-btn">
          <el-button type="primary" size="large" @click="submitForm">
            <i class="iconfont icon-login-button"></i>
            <b>登录</b>
          </el-button>
        </div>
      </el-form>
    </div>
  </div>
</template>

<script>
import { mixin } from "../mixins/index";
import { getLoginStatus } from "../api/index";
export default {
  mixins: [mixin],
  data: function () {
    return {
      ruleForm: {
        username: "admin",
        password: "123456",
      },
      rules: {
        username: [
          {
            required: true,
            message: "请输入用户名",
            trigger: "blur",
          },
        ],
        password: [
          { required: true, message: "请输入密码", trigger: "blur" },
        ],
      },
    };
  },
  methods: {
    submitForm () {
      let params = new URLSearchParams();
      params.append("name", this.ruleForm.username);
      params.append("password", this.ruleForm.password);
      getLoginStatus(params)
        .then((res) => {
          if (res.code == 1) {
            localStorage.setItem(
              "userName",
              this.ruleForm.username
            );
            this.$router.push("/Info");
            this.notify("登录成功", "success");
          } else {
            this.notify("登录失败", "error");
          }
        })
        .catch((e) => {
          if (e.data == undefined) {
            if (
              e ==
              "TypeError: Cannot read properties of undefined (reading 'status')"
            ) {
              e = "Network Error";
            }
            this.$message({
              showClose: true,
              message: e,
              type: "error",
              duration: 5000,
            });
          } else {
            this.$message({
              showClose: true,
              message: e.data,
              type: "error",
              duration: 5000,
            });
          }
        });
    },
  },
};
</script>

<style scoped>
.login-wrap {
  position: relative;
  background: linear-gradient(135deg, #1e3c72 0%, #2a5298 100%);
  background-attachment: fixed;
  background-position: center;
  background-size: cover;
  width: 100vw;
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
}

.ms-login {
  background: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(10px);
  border-radius: 15px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  padding: 40px;
  width: 400px;
  box-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.37);
}

.ms-title {
  text-align: center;
  color: white;
  margin-bottom: 30px;
}

.ms-title i {
  font-size: 40px;
  color: #1db954;
  margin-right: 10px;
}

.ms-title b {
  font-size: 32px;
  font-weight: bold;
}

.el-form-item {
  margin-bottom: 20px;
}

.el-input {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: white;
  border-radius: 8px;
}

.el-input::placeholder {
  color: rgba(255, 255, 255, 0.7);
}

.login-btn {
  text-align: center;
}

.el-button {
  background-color: #1db954;
  border: none;
  color: white;
  font-weight: bold;
  border-radius: 8px;
  padding: 12px 20px;
  transition: background-color 0.3s ease;
}

.el-button:hover {
  background-color: #1ed760;
}

.el-button i {
  font-size: 20px;
  margin-right: 5px;
}

.el-button b {
  font-size: 20px;
}
</style>
